package com.hzit.service.impl;

import com.hzit.mapper.UserMapper;
import com.hzit.pojo.User;
import com.hzit.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@Service
public class UserServiceImpl implements UserService {
	@Autowired
	private UserMapper userMapper;
	//1. 转账方法
	@Override
	@Transactional
	public void transfer(int money, int uid1,int uid2) {
		//1.1 转出
		User user1 = new User();
		user1.setBalance(-money);
		user1.setUid(uid1);
		userMapper.update(user1);
		int i = 10 / 0;
		//1.2 转入
		User user2 = new User();
		user2.setBalance(money);
		user2.setUid(uid2);
		userMapper.update(user2);
	}
}
